#include<bits/stdc++.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983,Mod=998244353;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
int n;
int a[N],b[N],lg[N];
int st1[N][21],st2[N][21];
inline int calc1(int l,int r){
	int k=lg[r-l+1];
	return min(st1[l][k],st1[r-(1<<k)+1][k]);
}
inline int calc2(int l,int r){
	int k=lg[r-l+1];
	return min(st2[l][k],st2[r-(1<<k)+1][k]);
}
set<int>S[N];
int len[N],gg[N],ans[N]; 
signed main(){
	freopen("min.in","r",stdin);
	freopen("min.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	lg[0]=-1;
	For(i,1,N-5) lg[i]=lg[i>>1]+1; 
	n=read();
	bool flag1=0,flag2=0;
	For(i,1,n) st1[i][0]=a[i]=read();
	For(i,1,n)st2[i][0]=b[i]=read();
	For(j,1,20){
		For(i,1,n){
			if(i+(1<<j)-1>n) break;
			st1[i][j]=min(st1[i][j-1],st1[i+(1<<(j-1))][j-1]);
			st2[i][j]=min(st2[i][j-1],st2[i+(1<<(j-1))][j-1]);
		}
	}
	For(i,1,n) if(b[i]!=1) flag1=1;
	For(i,1,n) if(b[i]!=1000000000) flag2=1;
	if(!flag1){
		For(i,1,n){
			printf("%lld\n",calc1(1,n)-1);
		}
		return 0;
	}if(!flag2){
		For(i,1,n) gg[i]=a[i];
		sort(gg+1,gg+n+1);
		int m=unique(gg+1,gg+n+1)-gg-1;
		For(i,1,n) a[i]=lower_bound(gg+1,gg+n+1,a[i])-gg;
		For(i,1,n) S[a[i]].insert(i);
		set<int>s;
		multiset<int>mx;
		len[0]=1e16;
		s.insert(n+1);
		s.insert(0);
		mx.insert(n);
		For(i,1,m){
			for(auto v:S[i]){
				auto o=s.lower_bound(v);
				mx.erase(mx.lower_bound((*o)-(*prev(o))-1));
				mx.insert((*o)-v-1);
				mx.insert(v-(*prev(o))-1);
				s.insert(v);
			}
			len[i]=*mx.rbegin();
//			cout<<len[i]<<" "; 
		}
		int k=0;
		Rof(i,n,1){
			while(k+1<m&&len[k+1]>=i){
				k++;
			}
			ans[i]=gg[k+1];
		}
		For(i,1,n){
			printf("%lld\n",b[1]-ans[i]);
		}return 0;
	}
	For(k,1,n){
		int ans=1e16;
		For(i,1,n-k+1){
			ans=min(ans,abs(calc1(i,i+k-1)-calc2(i,i+k-1)));
		}
		printf("%lld\n",ans);
	}
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

